package com.youthburin.base.taglib;

import java.util.Locale;

import javax.servlet.jsp.tagext.BodyTagSupport;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

public class BaseTag extends BodyTagSupport {
	private static final long serialVersionUID = 1L;
	private ApplicationContext context;

	public String getMessage(String code) {
		return getContext().getMessage(code, null, code,
				(Locale) pageContext.getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME));
	}

	public ApplicationContext getContext() {
		if (context == null)
			context = WebApplicationContextUtils.getWebApplicationContext(this.pageContext.getServletContext());

		return context;
	}
}
